package com.rangers.learning.psql.example;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

public interface UserDetailRepo extends CrudRepository<UserDetail, Long> {
	@Query(value = "select * from user_detail where label ->> 'name' = :name", nativeQuery = true)
	List<UserDetail> findByLableName(@Param("name")String labelName);
	
	@Query(value = "select * from user_detail where userinfo ->> 'sex' = :sex", nativeQuery = true)
	List<UserDetail> findByUsersex(@Param("sex")String sex);

	@Modifying
	@Query("update #{#entityName} set userinfo = ?2 where id= ?1")
	int updateUserinfo(Long id, UserInfo userinfo);

	@Modifying
	@Query("update #{#entityName} set name = ?1")
	void updateUsername(String name);
}
